<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算器困境</title>
</head>
<body>
    <h1 class="mytitle">按下F12打开控制台查看</h1>
<script>
    //计数器困境
    function fun(){
            var num = 0; //设置计数器的初始值
            function fun1(){//闭包
                num++; 
                console.log('被调用了'+num+'次');
            };
            setInterval(fun1,1000);//每隔1s增加1
        };
        fun();
</script>   
</body>
</html>